<template>
  <div class="commentcom">
    <div class="top">
      <div class="img">
        <img @click="clickImg" :src="baseURL + item.author.avatar" alt="" />
      </div>
      <div class="msg">
        <div class="name">{{ item.author.nickname }}</div>
        <div class="time">{{ item.created_at | hmfilter }}</div>
      </div>
      <div class="star">
        {{ item.star }} <i class="iconfont iconicon_dianzanliang"></i>
      </div>
    </div>
    <div class="bottom">
      <div class="message">
        {{ item.content }}
      </div>
      <div class="replay" v-if="item.children_comments.length > 0">
        <div
          class="item"
          v-for="(subitem, subindex) in item.children_comments"
          :key="subindex"
        >
          <span>{{ subitem.author }}：</span>{{ subitem.content }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ['item'],
  data () {
    return {
      baseURL: process.env.VUE_APP_URL
    }
  },
  methods: {
    clickImg () {
      // 向外界暴露一个方法： imgclick
      this.$emit('imgclick', this.item)
    }
  }
}
</script>

<style lang="less" scoped>
.commentcom {
  padding-bottom: 20px;
  font-size: 12px;
  .top {
    display: flex;
    align-items: center;
    .img {
      img {
        width: 35px;
        height: 35px;
        border-radius: 50%;
        margin-right: 10px;
      }
    }
    .msg {
      flex: 1;
      .name {
        font-weight: 700;
      }
      .time {
        color: #ccc;
      }
    }
    .star {
      color: #ccc;
    }
  }
  .bottom {
    padding-left: 45px;
    .message {
      font-size: 16px;
      padding: 15px 0;
      word-break: break-all; // 作用：单词换行
      word-wrap: break-word; // 作用：特殊字符换行
    }
    .replay {
      background-color: #f7f4f5;
      padding: 15px;
      padding-top: 0;
      .item {
        padding-top: 15px;
        span {
          font-weight: 700;
        }
      }
    }
  }
}
</style>
